package com.seven.alert.condition;

import lombok.extern.log4j.Log4j2;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.util.StringUtils;

/**
 * @Author seven
 * @Date 2021/1/21 13:41
 * @Description
 * @Version 1.0
 */
@Log4j2
public class AliSmsCondition implements Condition {
    @Override
    public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
        String regionId = conditionContext.getEnvironment().getProperty("alert.sms.ali.regionId");
        String accessKeyId = conditionContext.getEnvironment().getProperty("alert.sms.ali.accessKeyId");
        String secret = conditionContext.getEnvironment().getProperty("alert.sms.ali.secret");
        String signName = conditionContext.getEnvironment().getProperty("alert.sms.ali.signName");
        String templateCode = conditionContext.getEnvironment().getProperty("alert.sms.ali.templateCode");
        log.info("是否开启阿里短信通知服务：" + (!StringUtils.isEmpty(regionId) &
                !StringUtils.isEmpty(accessKeyId) &
                !StringUtils.isEmpty(secret) &
                !StringUtils.isEmpty(signName) &
                !StringUtils.isEmpty(templateCode)));
        return !StringUtils.isEmpty(regionId) &
                !StringUtils.isEmpty(accessKeyId) &
                !StringUtils.isEmpty(secret) &
                !StringUtils.isEmpty(signName) &
                !StringUtils.isEmpty(templateCode)
                ;
    }
}
